package resp

type Resp interface {
	New(code int, msg string, data any, other any) To
	NewOK(list ...any) To
	NewErr(code int, msg string) To
}

type To interface {
	SetCode(code int)
	SetMsg(msg string)
	SetData(data any)
	SetOther(other any)

	ToJson() []byte
	Value() any        //返回可以JSON编码的对象
	Gin() (int, any)   //返回http状态码code和可以JSON编码的对象
	GinOK() (int, any) //返回http状态码200和可以JSON编码的对象
}

var Std = NewStandard()

var Simple = NewSimple()

const (
	ContentType_JSON = `application/json; charset=utf-8`
)

var _defaultResp Resp

func init() {
	_defaultResp = Std
}

func SetDefaultResp(r Resp) {
	_defaultResp = r
}

func New(code int, msg string, data any, other any) To {
	return _defaultResp.New(code, msg, data, other)
}
func NewOK(list ...any) To {
	return _defaultResp.NewOK(list...)
}
func NewErr(code int, msg string) To {
	return _defaultResp.NewErr(code, msg)
}
